/********************************************************************
	filename: 	playlistmanager.cpp
	author:		zouyf
	created:	2009-9-20  12:21:28
	describ:

*********************************************************************/
#include "stdafx.h"
#include "playlist.h"
#include "playlistmanager.h"

FPlayListManager::FPlayListManager() : m_pCurPlayList(NULL)
{

}

FPlayListManager::~FPlayListManager()
{
	for (std::vector<IPlayList*>::iterator it = m_playListVec.begin(); it != m_playListVec.end(); ++it)
	{
		delete *it;
		*it = NULL;
	}
}

void FPlayListManager::Init(IApplication *pApp)
{
	m_pApp = pApp;
}

int FPlayListManager::GetPlayListCount()
{
	return m_playListVec.size();
}

IPlayList* FPlayListManager::GetPlayList(int Idx)
{
	IPlayList *pPlayList = NULL;
	if (Idx >= 0 && Idx < m_playListVec.size())
	{
		pPlayList = m_playListVec[Idx];
	}

	return pPlayList;
}

IPlayList* FPlayListManager::GetCurPlayList()
{
	return m_pCurPlayList;
}

void FPlayListManager::SetCurPlayList(IPlayList* pPlayList)
{
	ATLASSERT(pPlayList != NULL);
	m_pCurPlayList = pPlayList;
}

IPlayList* FPlayListManager::AddPlayList(const wchar_t* pName)
{
	FPlayList *playList = new FPlayList;
	playList->SetName(pName);
	m_playListVec.push_back(playList);
	return playList;
}

BOOL FPlayListManager::DelPlayList(IPlayList* pPlayList)
{
	BOOL bSuc = FALSE;
	for (std::vector<IPlayList*>::iterator it = m_playListVec.begin(); it != m_playListVec.end(); ++it)
	{
		if (pPlayList == *it)
		{
			m_playListVec.erase(it);
			bSuc = TRUE;
			return bSuc;
		}
	}

	return bSuc;
}

BOOL FPlayListManager::DelPlayList(int Idx)
{
	BOOL bSuc = FALSE;
	if (Idx >= 0 && Idx < m_playListVec.size())
	{
		m_playListVec.erase(m_playListVec.begin() + Idx);
		bSuc = TRUE;
	}

	return bSuc;
}

IApplication* FPlayListManager::GetApplication()
{
	return m_pApp;
}